Page({
  data: {
    name: '',
    time: '',
    textContent: '',
    uploadedFilePaths: []
  },

  onLoad(options) {
    const draftId = options.id; 
    if (draftId) {
      this.getDraft(draftId);
    }
  },

  getDraft(draftId) {
    wx.request({
      url: '', 
      method: 'GET',
      data: {
        id: draftId
      },
      success: (res) => {
        if (res.statusCode === 200) {
          const { content, name, time, fileUrls } = res.data;
          this.setData({
            textContent: content,
            name: name,
            time: time,
            uploadedFilePaths: fileUrls
          });
        } else {
          wx.showToast({
            title: '获取草稿失败',
            icon: 'none'
          });
        }
      },
      fail: (err) => {
        console.error('获取草稿失败：', err);
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        });
      }
    });
  }
});
